package cn.com.dhc.danlu.activity.delivery.order.utill;

import android.text.TextUtils;

import java.util.ArrayList;
import java.util.List;

import cn.com.dhc.danlu.activity.delivery.order.bean.OrderDataBean;
import cn.com.dhc.danlu.activity.delivery.order.bean.OrderFuncBean;
import cn.com.dhc.danlu.activity.delivery.order.bean.OrderStatusBean;
import cn.com.dhc.danlu.activity.delivery.order.decorate.Visitable;
import cn.com.dhc.danlu.util.CommonConst;
import cn.com.hd.mall.web.webservices.entity.response.order.OrderListResponse;
import cn.com.hd.mall.web.webservices.entity.response.order.OrderListResponse.PaymentOrderListBean.MerchListBean;

/**
 * author: 李一方(<a href="mailto:liyifang@danlu.com">liyifang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-02-14 15:38
 * <p>
 * <p>
 * 内容描述区域
 * </p>
 */
public class Modle2BeanUtil {
    public static List<Visitable> convert(OrderListResponse original) {
        List<Visitable> data = new ArrayList<>();

        for (OrderListResponse.PaymentOrderListBean paymentModel : original.getPaymentOrderList()) {
            String payStatus2Middle = paymentModel.getPayStatus2Middle();
            boolean isPayingStatus = judgeIsPayingStatus(payStatus2Middle);

            String payType = paymentModel.getPayType();
            String paymentNo = paymentModel.getPaymentNo();

            int goodsLength = paymentModel.getMerchList().size();

            OrderStatusBean statusBean = new OrderStatusBean();
            statusBean.setCancelStatus(paymentModel.getCancelStatus());
            statusBean.setErrorStatus(paymentModel.getErrorStatus());
            statusBean.setOrderNo(paymentModel.getOrderNo());
            statusBean.setOrderStatus(paymentModel.getOrderStatus());
            statusBean.setPaymentNo(paymentModel.getPaymentNo());
            statusBean.setReceiveStatus(paymentModel.getReceiveStatus());
            statusBean.setPayStatus2Middle(payStatus2Middle);
            statusBean.setPayWay(paymentModel.getPayWay());
            statusBean.setButtomList(paymentModel.getButtomList());
            statusBean.setPayType(payType);
            statusBean.setGoodsLength(goodsLength);

            data.add(statusBean);

            for (MerchListBean merchModel : paymentModel.getMerchList()) {
                OrderDataBean bean = new OrderDataBean();
                bean.setCostPrice(merchModel.getCostPrice());
                bean.setMerchBarCode(merchModel.getMerchBarCode());
                bean.setMerchCount(merchModel.getMerchCount());
                bean.setMerchName(merchModel.getMerchName());
                bean.setPicUrl(merchModel.getPicUrl());
                bean.setUnitPrice(merchModel.getUnitPrice());
                bean.setOrderNo(paymentModel.getOrderNo());
                bean.setPromotionType(merchModel.getPromotionType());
                bean.setAveragePrice(merchModel.getAveragePrice());

                data.add(bean);
            }

            OrderFuncBean funcBean = new OrderFuncBean();
            funcBean.setOrderStatus (paymentModel.getOrderStatus ());
            funcBean.setButtomList(paymentModel.getButtomList());
            funcBean.setOrderMerchCount(paymentModel.getPaymentOrderMerchCount());
            funcBean.setTotalPrice(paymentModel.getPaymentOrderTotalPrice());
            funcBean.setPayingStatus(isPayingStatus);
            funcBean.setPaymentNo(paymentNo);
            funcBean.setPayType(payType);
            funcBean.setOrderNo(paymentModel.getOrderNo());
            funcBean.setGoodsLength(goodsLength);
            data.add(funcBean);
        }

        return data;
    }

    private static boolean judgeIsPayingStatus(String payMiddleStatus) {
        //说明当前是支付中状态
        return (!TextUtils.isEmpty(payMiddleStatus) && CommonConst.PaymentConst.PAYMENT_ORDER_STATUS_PAYING.equals(payMiddleStatus));
    }

}
